def hex2string(hexstr):
    lens = (len(hexstr) + 1) / 2
    lens = int(lens)
    j = 0
    list_ = []
    for i in range(lens):
        oneLineTiaojian = ord(hexstr[j]) & ord('@')
        oneLinebd1 = ord(hexstr[j]) + 9
        oneLinebd2 = ord(hexstr[j])
        oneValue = oneLinebd1 if oneLineTiaojian else oneLinebd2
        tmp = (oneValue << 4) % 256  # << >> ??????????????0-7?8?
        oneResValue = tmp if tmp < 128 else tmp - 256  # ?c++?tmp?char????????python??tmp?int??????

        j += 1

        towLinetiaojian = ord(hexstr[j]) & ord('@')
        towLinebd1 = ord(hexstr[j]) + 9
        towLinebd2 = ord(hexstr[j])
        towValue = towLinebd1 if towLinetiaojian else towLinebd2

        towResValue = towValue & 0xF
        res = oneResValue | towResValue
        j += 1
        list_.append(str(res))
    return list_


def decryptPassword(strEncrypedText):
    res_list = hex2string(strEncrypedText)
    pwd_list = []
    for i in range(1, int(len(res_list)), 2):
        r1 = int(res_list[i]) ^ 86
        pwd_list.append(chr(r1))
    res = ''.join(pwd_list)
    return res


if __name__ == '__main__':
    # r = decryptPassword('dc67cb6432652462b563fb602161db6ed46f581612336f24d82f553f')
    r = decryptPassword('3167A364E8654C624263A660')
    # print(r)
